package qq.qqClient;

import qq.Message;
import qq.MessageTypes;
import qq.User;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.DatagramSocket;
import java.net.Socket;
import java.util.Scanner;

public class UserClientService {

    Socket socket;
    String serverPort;
    int serverIP;
    Scanner scanner = new Scanner(System.in);

    public UserClientService() {
    }

    public UserClientService(String port, int ip) {
        this.serverPort = port;
        this.serverIP = ip;
        socket = new Socket();
    }
    public static void start() {

    }
    public boolean checkUser(User user){
        try {
            ObjectOutputStream outputStream = new ObjectOutputStream(socket.getOutputStream());
            outputStream.writeObject(user);

            // 读取服务端回送的对象
            ObjectInputStream inputStream = new ObjectInputStream(socket.getInputStream());
            Message message = (Message) inputStream.readObject();
            if (message != null && message.getMessageType().equals(MessageTypes.MESSAGE_LOGIN_SUCCEED)){
                // 登录成功
                return true;
            }else {
                return false;
            }
        } catch (IOException | ClassNotFoundException e) {
            e.printStackTrace();
        }
        return false;
    }

    public void sendMessage(Message message, DatagramSocket socket) throws IOException {

    }
}
